package single;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author lyx
 * @Date 2021/6/27 13:23
 */
public enum EnumSingleTest {
    INSTANCE;
    public EnumSingleTest getInstance(){
        return INSTANCE;
    }
}

class Test{

    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        //正常拿枚举对象
        EnumSingleTest instance = EnumSingleTest.INSTANCE;

        //反射不能破坏枚举，下面代码是尝试破坏
        //反射枚举的构造方法，通过构造方法获取枚举对象，注意：枚举的构造方法，是有2个参数的！
        Constructor <EnumSingleTest> constructor =EnumSingleTest.class.getDeclaredConstructor(String.class,int.class);
        //获取权限
        constructor.setAccessible(true);
        //通过反射拿枚举对象
        EnumSingleTest enumsingle = constructor.newInstance();
        System.out.println(instance);
        System.out.println(enumsingle);

    }
}